/* EasyWay Game Engine
 * Copyright (C) 2006 Daniele Paggi.
 *  
 * Written by: 2006 Daniele Paggi<dshnt@hotmail.com>
 *   
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.easyway.system;

/**
 * @author Daniele Paggi
 * 
 */
class ASincroL extends Sincro {
	
	public static int cpf = 1000;

	/** create a new instance of Sincro */
	public ASincroL() {
		super();
	}

	/** main loop of game */
	public void run() {

		last = System.currentTimeMillis();
		CurrentTime = LastTime = System.currentTimeMillis();
		ElaspedTime = 0;
		TimeOutOpController tc = null;

		new ASincroD();
		while (!core.initialized) {
			Thread.yield();
		}

		while (loop) {
			ricaveElaspedTime();
			if (ElaspedTime < 1000/cpf) {
				
				try {
					Thread.sleep((long) ( 1000/cpf - Math.max(ElaspedTime,1)));
					Thread.yield();
				} catch (Exception e) {

				}
			}
			if (timeOut >= 1000)
				(tc = new TimeOutOpController(timeOut, this)).start();
			core.coreLoop();
			if (tc != null) {
				tc.stop();
				tc = null;
			}
			fps();
		}
	}

}
